---
title: "获取泛型类型"
date: 2919-6-10
categories:
- java
tags:
---

<div id="content">
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org1746574">ParameterizedType represents a parameterized type such as</a></li>
<li><a href="#orgdc433c5">Collection&lt;String&gt;.</a></li>
<li><a href="#org9c501a9">A parameterized type is created the first time it is needed by a</a></li>
<li><a href="#org12a762c">reflective method, as specified in this package. When a</a></li>
<li><a href="#org205cfbb">parameterized type p is created, the generic type declaration that</a></li>
<li><a href="#org3d0819d">p instantiates is resolved, and all type arguments of p are created</a></li>
<li><a href="#org76ad971">recursively.</a></li>
</ul>
</div>
</div>
<blockquote>
<p>
<a href="https://xebia.com/blog/acessing-generic-types-at-runtime-in-java/">https://xebia.com/blog/acessing-generic-types-at-runtime-in-java/</a>
</p>
</blockquote>
<p>
#+BEGIN_QUOTE
/**
</p>
<div class="outline-2" id="outline-container-org1746574">
<h2 id="org1746574">ParameterizedType represents a parameterized type such as</h2>
</div>
<div class="outline-2" id="outline-container-orgdc433c5">
<h2 id="orgdc433c5">Collection&lt;String&gt;.</h2>
<div class="outline-text-2" id="text-orgdc433c5">
<p>
*
</p>
</div>
</div>
<div class="outline-2" id="outline-container-org9c501a9">
<h2 id="org9c501a9">A parameterized type is created the first time it is needed by a</h2>
</div>
<div class="outline-2" id="outline-container-org12a762c">
<h2 id="org12a762c">reflective method, as specified in this package. When a</h2>
</div>
<div class="outline-2" id="outline-container-org205cfbb">
<h2 id="org205cfbb">parameterized type p is created, the generic type declaration that</h2>
</div>
<div class="outline-2" id="outline-container-org3d0819d">
<h2 id="org3d0819d">p instantiates is resolved, and all type arguments of p are created</h2>
</div>
<div class="outline-2" id="outline-container-org76ad971">
<h2 id="org76ad971">recursively.</h2>
<div class="outline-text-2" id="text-org76ad971">
<p>
#+END_QUOTE
</p>
<div class="org-src-container">
<pre class="src src-java"><span style="font-weight: bold; text-decoration: underline;">@SuppressWarnings</span>(<span style="font-style: italic;">"unchecked"</span>)
 <span style="font-weight: bold;">public</span> <span style="font-weight: bold;">GenericJpaDao</span>() {
   <span style="font-weight: bold;">this</span>.entityBeanType = ((<span style="font-weight: bold; text-decoration: underline;">Class</span>&lt;<span style="font-weight: bold; text-decoration: underline;">T</span>&gt;) ((<span style="font-weight: bold; text-decoration: underline;">ParameterizedType</span>) getClass()
       .getGenericSuperclass()).getActualTypeArguments()[0]);
 }
</pre>
</div>
</div>
</div>
</div>
<div class="status" id="postamble">
<p class="date">Date: 2919-6-10</p>
<p class="author">Author: amo</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
